class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int sum = 0, total = 0;
        for (int i = 0; i < nums.size(); i++) sum += nums[i];
        for (int i = 0; i < nums.size(); i++)
        {
            if (total * 2 + nums[i] == sum) return i;
            total += nums[i];
        }
        return -1;
    }
};